/* eslint-disable max-classes-per-file */
/*
 * @Description:基础类
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2022-12-17 09:56:08
 * @LastEditors: wiz
 * @LastEditTime: 2023-12-18 12:14:53
 */
import { Grid, I_M2OList, I_SLCList, T_conf, Tsrv } from '../config';

export class T_bgdBase {
  // obaseGrid实例
  protected oBaseGrid: any;

  // 多对一
  protected m2oList: I_M2OList[];

  // 字段附加列表
  protected slcList: I_SLCList[];

  protected grid: Grid;

  protected toolbar: any;

  protected gridID: string;

  protected globalSearchText: string;

  protected funName: string;

  protected tableName: string;

  protected funID: string;

  protected dbType: string;

  protected actionsCfg: any;

  protected lang: string;

  protected mainFunName: string;

  // 当前选中的行
  protected currSelectRowIdx: number = NaN;

  // // 更新范围
  protected scope: any;

  // obj 为oBaseGrid 实例
  constructor(obj: any) {
    this.oBaseGrid = obj;

    this.slcList = [];
    this.m2oList = [];
    this.actionsCfg = {};
    this.scope = T_conf.scope();
  }

  public setGlobalSearchText(p: string): T_bgdBase {
    this.toolbar.setSearchText(p);
    return this;
  }

  public asnycGlobalSeachText(p: string) {
    this.globalSearchText = p;
  }

  public getGlobalSearchText(): string {
    return this.globalSearchText;
  }

  public setGrid(p: Grid): T_bgdBase {
    this.grid = p;
    return this;
  }

  public setToolbar(p: any): T_bgdBase {
    this.toolbar = p;
    return this;
  }

  public getToolbar(): any {
    return this.toolbar;
  }

  public getGrid(): Grid {
    return this.grid;
  }

  public setGridID(p: string): T_bgdBase {
    this.gridID = p;
    return this;
  }

  public getGridID(): string {
    return this.gridID;
  }

  public setDbType(p: string): T_bgdBase {
    this.dbType = p;
    return this;
  }

  public getDbType(): string {
    return this.dbType;
  }

  public setMainFunName(p: string): T_bgdBase {
    this.mainFunName = p;
    return this;
  }

  public getMainFunName(): string {
    return this.mainFunName;
  }

  // 对应this.funName
  public setFunName(p: string): T_bgdBase {
    this.funName = p;
    this.oBaseGrid.funName = p;
    return this;
  }

  public getFunName(): string {
    return this.funName;
  }

  // 对应原来this.name
  public setTableName(p: string): T_bgdBase {
    this.tableName = p;
    this.oBaseGrid.tableName = p;
    return this;
  }

  public getTableName(): string {
    return this.tableName;
  }

  public setFunID(p: string): T_bgdBase {
    this.funID = p;
    return this;
  }

  public getFunID(): string {
    return this.funID;
  }

  public setCurrRowIdx(p: number): T_bgdBase {
    this.currSelectRowIdx = p;
    return this;
  }

  public getCurrRowIdx(): number {
    return this.currSelectRowIdx;
  }

  /**
   * setScope 设置更新范围，主要为排序作用，只针对于initfilter
   */
  public setScope(field: string, value: any): T_bgdBase {
    this.scope.field = field;
    this.scope.value = Tsrv.utils.toString(value);
    return this;
  }

  /**
   * getScope 获取更新范围
   */
  public getScope(): { field: string; value: any } {
    return this.scope;
  }

  public setActionCfg(config: any): T_bgdBase {
    if (Tsrv.utils.isPlainObject(config)) {
      this.actionsCfg = config;
    }
    return this;
  }

  public getActionCfg(): any {
    return this.actionsCfg;
  }

  public setM2oList(...p: I_M2OList[]): T_bgdBase {
    this.m2oList.push(...p);
    return this;
  }

  public getM2oList(): I_M2OList[] {
    return this.m2oList;
  }

  public setSlcList(...p: I_SLCList[]): T_bgdBase {
    this.slcList.push(...p);
    return this;
  }

  public getSlcList(): I_SLCList[] {
    return this.slcList;
  }

  public getLang(): string {
    return this.lang;
  }

  public setLang(p: string): T_bgdBase {
    this.lang = p;
    return this;
  }
}
export interface I_bgdBase extends T_bgdBase {}
